<?php
defined('PATH') or exit('Access Denied');
abstract class Action{
 
	protected $view;
	
	function __construct(){
		global $lang,$SID,$ACT,$ACTVAL,$METHOD,$METVAL,$TEMPLATE,$Mitype; 
		isset($_SESSION['Themes'])?$TEMPLATE=$_SESSION['Themes']:null;
		$this->view=new Smarty();
		$this->view->template_dir=_PATH_."/".Controller::$_C['SMARTY']['Templates_dir'].$TEMPLATE.'/';
		$this->view->compile_dir=_PATH_."/".Controller::$_C['SMARTY']['Templates_c'];
		$this->view->compile_check=Controller::$_C['SMARTY']['CACHE_CHECK'];
		$this->view->cache_dir=_PATH_."/".Controller::$_C['SMARTY']['Cache_dir'];

        $this->view->assign('licensed',Controller::$licensed);
        $this->view->assign('site_config', SiteConfig::getAll());
		$this->view->assign("L",$lang);//向模板中添加语言包变量
		$this->view->assign("thisurl",enUrl(getUrl()));
		$this->view->assign("SID",$SID);
		$this->view->assign($ACT,$ACTVAL);
		$this->view->assign($METHOD,$METVAL);
		$this->assign('time', time()); 
		$this->view->assign("template",PATH."/".Controller::$_C['SMARTY']['Templates_dir'].$TEMPLATE.'/');
		$this->view->assign("path",PATH);
		//$this->view->assign("URL",$_SERVER['PHP_SELF']);
		@$this->view->register_function('url','_smarty_function_url');
		$tempconf=$GLOBALS['TEMPCONF'];
		header('Content-Type:'.$tempconf[$_SESSION['Themes']][0].';Charset =utf-8');
		//header("Content-type:".$Mitype[$TEMPLATE].";charset=utf-8");
		//执行初始化方法 
		$this->init();
	 
	}
	/**
	 * 抽象一个控制器初始化方法
	 */
	abstract  function init();
	
	public function display($template, $cache_id = null, $compile_id = null, $parent = null){
		$this->view->display($template, $cache_id = null, $compile_id = null, $parent = null);
	}
	
	public function assign($name,$value){
		$this->view->assign($name, $value);
	}
	


	function Message($content,$title='',$goto='',$gotime=0){
		if (empty($title)) $title="提示信息";
		$this->assign("content",$content);
		$this->assign("title",$title);
		$this->assign("tourl",$goto);
		$this->assign("gotime",$gotime);
		$this->display("message.htm"); 
		exit();
	}
}